import http from '@/shopro/request/index'
import share from '@/shopro/share';
import store from "@/shopro/store";

const state = {
	homeTemplate: [], // 首页模板数据
	userTemplate: [], // 个人中心模板数据
	shareInfo: {} ,// 默认分享数据
	areaData:[]//城市数据
}
const getters = {
	homeTemplate:  state => state.homeTemplate,
	userTemplate: state =>state.userTemplate,
	shareInfo: state => state.shareInfo,
	areaData: state => state.areaData,
}


const actions = {
	// 初始化数据
	async appInit({
		commit,
		dispatch
	}, options) {
		// const res = await http('group.area');
		// if (res.code === 1) {
		// 	let {provinceData, cityData, areaData} = res.data;
		// 	let addressAreaList = []
		// 	provinceData.forEach((item, index) => {
		// 		addressAreaList.push({...item, children: []});
		// 		addressAreaList[index].children.push(...cityData[index]);
		// 		addressAreaList[index].children.forEach((item1, index1) => {
		// 			item1['children'] = [];
		// 			item1.children.push(...areaData[index][index1]);
		// 		});
		// 	});
		// 	store.commit('AREARDATA',addressAreaList)
		// 	return res.data;
		// }
		return false;
	},

	// 同步路由到后端
	syncPages({
		commit
	}) {
		http('common.syncPages', {
			data: ROUTES,
		})
	},
}


const mutations = {
	AREARDATA(state, payload) {
		state.areaData = payload;
	},
	USER_DATA(state, payload) {
		state.userTemplate = payload;
	},
	shareInfo(state, shareInfo) {
		state.shareInfo = shareInfo;
	}
}


export default {
	state,
	mutations,
	actions,
	getters
}
